
//碰撞盒多边形
class CCOLLINSION_POLY extends CCOLLISION {


	//形状碰撞开关
	private shape_collision:boolean=false
	
	
	public constructor(ptr:CBASE,x1y1:egret.Point,x2y2:egret.Point,x3y3:egret.Point,x4y4?:egret.Point,x5y5?:egret.Point,color?:number) {
		  super(ptr)
		  this.judgetype=judgetype.poly
		  this.shape=new egret.Shape();
		  this.setshape(x1y1,x2y2,x3y3,x4y4,x5y5,color);
		  this.parent.addChild(this.shape)
		  this.shapeCollisionSwitch=false
	}

	public NormalVector():egret.Point[] //得到法向量
	{
		 var vectors=this.relpoint
		 var nomalvector:egret.Point[]=[]
		 for(var a=0;a<this.shapepoint.length-1;a++)
		  {
			 let b=new egret.Point
		     b=vectors[a+1].subtract(vectors[a])

		     let long=Math.sqrt(b.x*b.x+b.y*b.y)
		     b.x/=long,b.y/=long
		     let c=new egret.Point
		      //得到法向量
		      c.x=-b.y,c.y=b.x
		     nomalvector.push(c)
		
		 }
		     let b=new egret.Point
		     b=vectors[0].subtract(vectors[a-1])

		     let long=Math.sqrt(b.x*b.x+b.y*b.y)
		     b.x/=long,b.y/=long
		     let c=new egret.Point
		      //得到法向量
		      c.x=-b.y;
			  c.y=b.x;
		     nomalvector.push(c)
		 return nomalvector
	}
	public set shapeCollisionSwitch(a:boolean) //是否开启形状碰撞提示
	{
		
		this.shape_collision=a
		if(a)
		{
			this.shape.touchEnabled=true;
			this.shape.alpha=0.5
		}
		else{
			this.shape.touchEnabled=false;
		    this.shape.alpha=0
		}
		
	}
	public get relpoint():egret.Point[] //获得真实坐标
	{
		var vector:egret.Point[]=[]
		 for(let b=0;b<this.shapepoint.length;b++)
		  {
			  var local:egret.Point=new egret.Point
			   local.x=this.shapepoint[b].x+this.shape.x
		       local.y=this.shapepoint[b].y+this.shape.y
			   var anchoroff=new egret.Point(this.parent.anchorOffsetX,this.parent.anchorOffsetY)
			   var nowpoint= this.Pointrevolve(local,anchoroff,this.parent.rotation)
			   vector.push(new egret.Point(nowpoint.x+this.parent.x,nowpoint.y+this.parent.y))
			   //console.log(nowpoint.x,this.parent.x,nowpoint.y,this.parent.y)
		  }
	
		return vector
	}
	public get type():judgetype //得到type
	{
		return this.judgetype
	}
	public get r():number
	{
		return 0
	}
	public setshape(x1y1:egret.Point,x2y2:egret.Point,x3y3:egret.Point,x4y4?:egret.Point,x5y5?:egret.Point,color?:number)
	{
		  this.shape.graphics.clear();
		  this.shapepoint.splice(0,this.shapepoint.length)
          if(color==undefined)
		  this.shape.graphics.beginFill(0xff000,1);
		  else
          this.shape.graphics.beginFill(color,1);
		  this.shape.graphics.lineTo(x1y1.x,x1y1.y)
		  this.shape.graphics.lineTo(x2y2.x,x2y2.y)
		  this.shape.graphics.lineTo(x3y3.x,x3y3.y)
		  this.shapepoint.push(x1y1,x2y2,x3y3)
		  if(x4y4!=undefined)
		  {
			   this.shapepoint.push(x4y4)
			  this.shape.graphics.lineTo(x4y4.x,x4y4.y)
		  }
		   if(x5y5!=undefined)
		   {
			    this.shapepoint.push(x5y5)
			   this.shape.graphics.lineTo(x5y5.x,x5y5.y)
		   }
		  this.shape.graphics.lineTo(x1y1.x,x1y1.y)

		  this.shape.graphics.endFill();
		 
		  
		   this.shape.graphics.beginFill(0xfffff,1);
		  for(var a=0;a<this.shapepoint.length;a++)
		  {
			
			this.shape.graphics.drawCircle(this.shapepoint[a].x,this.shapepoint[a].y,5)
			
		  }
		  this.shape.graphics.endFill();
		 
	}


}